<template>
  <section>
    <div class="container">
      <div class="container-title">查询条件</div>
      <div class="container-body pd">
        <el-form
          label-position="right"
          label-width="120px"
          :model="searchForm"
          ref="searchForm"
          class="demo-form-inline"
        >
          <el-row :gutter="30">
            <el-col :span="5">
              <el-form-item label="商品名称：" size="small" prop="goodsName">
                <el-input
                  v-model="searchForm.goodsName"
                  placeholder="请输入商品名称"
                  prefix-icon="el-icon-search"
                  size="small"
                />
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item label="兑换地址：" size="small" prop="address">
                <el-input
                  v-model="searchForm.address"
                  placeholder="请输入兑换地址"
                  prefix-icon="el-icon-search"
                  size="small"
                />
              </el-form-item>
            </el-col>

            <el-col :span="5">
              <el-form-item label="兑换人姓名：" size="small" prop="name">
                <el-input
                  v-model="searchForm.name"
                  placeholder="请输入兑换人姓名"
                  prefix-icon="el-icon-search"
                  size="small"
                />
              </el-form-item>
            </el-col>

            <el-col :span="5">
              <el-form-item label="兑换人手机：" size="small" prop="phone">
                <el-input
                  v-model="searchForm.phone"
                  placeholder="请输入兑换人手机"
                  prefix-icon="el-icon-search"
                  size="small"
                />
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item label="快递单号：" size="small" prop="expressNum">
                <el-input
                  v-model="searchForm.phone"
                  placeholder="请输入快递单号"
                  prefix-icon="el-icon-search"
                  size="small"
                />
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item label="是否发货：" size="small" prop="isDeliver">
                <el-select
                  v-model="searchForm.isDeliver"
                  clearable
                  placeholder="请选择"
                  size="small"
                >
                  <el-option
                    v-for="item in options"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item
                label="兑换起始时间："
                size="small"
                prop="starttime"
              >
                <el-date-picker
                  v-model="searchForm.starttime"
                  type="date"
                  placeholder="选择日期"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item label="兑换结束时间：" size="small" prop="endtime">
                <el-date-picker
                  v-model="searchForm.endtime"
                  type="date"
                  placeholder="选择日期"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex" justify="center">
            <el-button
              class="is-tableBtn"
              size="small"
              @click="clearForm('searchForm')"
              >清空</el-button
            >
            <el-button
              class="is-tableBtn"
              type="primary"
              size="small"
              @click="GetComplaintList(searchForm)"
              >查询</el-button
            >
          </el-row>
        </el-form>
      </div>
    </div>
    <div class="container">
      <div class="container-title">兑换列表</div>
      <div class="container-body pd">
        <el-table
          :data="tableData"
          v-loading="loading"
          border
          style="width: 100%"
          size="small"
        >
          <el-table-column prop="cardNumber" label="卡编号" align="center">
          </el-table-column>
          <el-table-column prop="goodsName" label="商品名称" align="center">
          </el-table-column>
          <el-table-column prop="name" label="领取人姓名" align="center">
          </el-table-column>
          <el-table-column prop="phone" label="领取人手机" align="center">
          </el-table-column>
          <el-table-column prop="area" label="省市区" align="center">
          </el-table-column>
          <el-table-column prop="address" label="详细地址" align="center">
          </el-table-column>
          <el-table-column
            prop="logisticsState"
            label="是否发货"
            align="center"
          >
          </el-table-column>
          <el-table-column prop="num" label="数量" align="center">
          </el-table-column>
          <el-table-column prop="createTime" label="兑换时间" align="center">
          </el-table-column>
          <el-table-column label="操作" align="center" width="150">
            <template slot-scope="scope">
              <el-button
                class="btnwarning"
                type="warning"
                size="mini"
                @click="handleEdit(scope.$index, scope.row)"
                >处理投诉</el-button
              >
            </template>
          </el-table-column>
        </el-table>
        <div class="pageBox">
          <el-pagination
            background
            layout="prev, pager, next"
            :total="total"
            @current-change="currentPage"
          >
          </el-pagination>
          <div class="clear"></div>
        </div>
      </div>
    </div>
  </section>
</template>
<script>
export default {
  data() {
    return {
      page: 1,
      total: 0,
      createExchangePop: false, // 商品创建弹窗是否展示
      newExchangeForm: {
        cardNumber: "",
        goodsName: "",
        name: "",
        phone: "",
        area: "",
        address: "",
        expressNum: "",
        expressType: "",
        isDeliver: "",
        logisticsInfo: "",
        isvUUID: "",
        eclpSoNo: "",
        createTime: "",
      },
      showLogistics: false,
      newExchangeRule: {},
      options: [
        {
          value: false,
          label: "否",
        },
        {
          value: true,
          label: "是",
        },
      ],
      logisticsList: [], // 物流信息
      editID: "", // 当前编辑id
      tableData: [],
      loading: true,
      searchForm: {
        goodsName: "",
        address: "",
        name: "",
        phone: "",
        expressNum: "",
        isDeliver: "",
        starttime: "",
        endtime: "",
      },
    };
  },
  created() {
    this.GetComplaintList(this.searchForm);
  },
  methods: {
    createNew() {
      this.createExchangePop = true;
      this.newExchangeForm = {
        cardNumber: "",
        goodsName: "",
        name: "",
        phone: "",
        area: "",
        address: "",
        expressNum: "",
        expressType: "",
        isDeliver: "",
        logisticsInfo: "",
        isvUUID: "",
        eclpSoNo: "",
        createTime: "",
      };
    },
    async handleEdit(index, row) {
      let res = await this.$store.dispatch("PutComplaintList", {
        id: row.id,
      });
      if (res.success) {
         this.$message({
          message: "处理成功",
          type: "success",
        });
        this.GetComplaintList(this.searchForm); 
      } 
    },
    async handleLogs(index, row) {
      let res = await this.$store.dispatch("GetLogistics", {
        id: row.id,
      });
      if (res.success) {
        this.logisticsList = res.data || [];
        this.showLogistics = true;
      }
    },
    currentPage(page) {
      this.page = page;
      this.GetComplaintList(this.searchForm);
    },
    clearForm(formName) {
      // 清空筛选
      try {
        this.$refs[formName].resetFields();
      } catch (error) {
        console.log(error);
      }
    },
    resetFormESC(formName) {
      // 充值表单
      this.createExchangePop = false;
      this.$refs[formName].resetFields();
    },

    async GetComplaintList(searchForm) {
      this.loading = true;
      let skip = (this.page - 1) * 10;
      // 请求案例
      let res = await this.$store.dispatch("GetComplaintList", {
        goodsName: searchForm.goodsName,
        address: searchForm.address,
        name: searchForm.name,
        phone: searchForm.phone,
        expressNum: searchForm.expressNum,
        isDeliver: searchForm.isDeliver,
        starttime: searchForm.starttime,
        endtime: searchForm.endtime,
        skip,
      });
      if (res.success) {
        this.tableData = res.data.itmes || [];
        this.total = res.data.totalCount;
      }
      this.loading = false;
    },
    close() {
      this.resetFormESC("newExchangeForm");
    },
  },
};
</script>
<style lang="scss" scoped>
@import "@/assets/varibles.scss";
.btn {
  margin-bottom: $btnHeight;
  color: #ffff;
}
.btnwarning {
  color: $btnwarning;
}
.pageBox {
  padding-top: 10px;
  clear: both;
  .el-pagination {
    float: right;
  }

  .clear {
    clear: both;
  }
}
.logoistics {
  li {
    display: flex;
    .status {
      max-width: 300px;
    }
    justify-content: space-between;
    line-height: 50px;
    border-bottom: 1px solid #f4f4f4;
  }
}
</style>
